/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number[]}
 */
var postorderTraversal = function(root,res=[]) {
    if(!root)return res
    postorderTraversal(root.left,res)
    postorderTraversal(root.right,res)
    res.push(root.val)
    return res
    };


var postorderTraversal = function(root) {
    // 迭代 左右中
    const stack=[root],res=[]
    if(!root)return res
    while(stack.length){
        let node =stack.pop()
        res.push(node.val)
        node.left&&stack.push(node.left)
        node.right&&stack.push(node.right)
    }
    return res.reverse()
    };